{% extends 'base.html' %}
{% load docs %}

{% block layout_class %}full-width{% endblock %}
{% block title %}Getting started with Django{% endblock %}

{% block header %}
  <h1 class="visuallyhidden">Get started</h1>
  <div class="layout-2col">
    <div class="col two-third">
      <p>It’s <em>quick &amp; easy</em> to get up and running with <em>Django</em>.</p>
    </div>
    <div class="col one-third last-child">
      <a href="{% url 'download' %}" class="cta">Download <em>version {{ DJANGO_VERSION }}</em></a>
    </div>
  </div>
{% endblock %}

{% block content %}

  <div class="section">
    <h1>Getting started with Django</h1>
    {% url 'document-detail' lang='en' version='stable' url='intro/tutorial01' host 'docs' as tutorial1_url %}
    {% url 'homepage' host 'docs' as docs_homepage_url %}
    <p>Depending how new you are to Django, you can <a href="{{ tutorial1_url }}">try a tutorial</a>, or just <a href="{{ docs_homepage_url }}">dive into the documentation</a>.</p>

    <p>
      Want to learn more about Django? Read the overview to see whether Django is right for your project.
    </p>
    <a class="link-readmore" href="{% url 'overview' %}">Django overview</a>
  </div>

  <div class="section">
    <h2>Install Django</h2>
    <p>Before you can use Django, you’ll need to install it. Our complete installation guide covers all the possibilities; this guide will get you to a simple, minimal installation that’ll work while you walk through the introduction.</p>
    <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='intro/install' host 'docs' %}">Django installation guide</a>
  </div>

  <div class="section">
    <h2>Write your first Django app</h2>
    <p>Installed Django already? Good. Now <a href="{{ tutorial1_url }}">try this tutorial</a>, which walks you through creating a basic poll application. It’s got two parts:</p>
    <ol>
      <li>A public site that lets people view polls and vote in them.</li>
      <li>An administrative interface that lets you add, change and delete polls.</li>
    </ol>
    <a class="link-readmore" href="{{ tutorial1_url }}">Take the tutorial</a>
  </div>

  <div class="section">
    <h2>Sharpen your skills</h2>
    <p>The official <a href="{{ docs_homepage_url }}">Django documentation</a> covers everything you need to know about Django (and then some).</p>
     <a href="{{ docs_homepage_url }}" class="link-readmore">Read the docs</a>
  </div>

  <div class="section">
    <h2><span>Join the community</span></h2>
    <p>You can help <a href="{% url 'community-index' %}">make us better</a>. Find out about upcoming Django events, learn what’s on other Django developers’ minds, find and post jobs, and more.</p>
    <a href="{% url 'community-index' %}" class="link-readmore">Join us</a>
  </div>

  <div class="list-collapsing-header">
    <h2><span>Intro to Django</span></h2>
  </div>
  <ul class="list-collapsing">
  <li>
    <h2>Object-relational mapper</h2>
    <div class="collapsing-content">
      <p>Deﬁne your data models entirely in Python. You get a rich, dynamic database-access API for free — but you can still write SQL if needed.</p>
      <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/db/models' host 'docs' %}">Read more</a>
      {% pygment 'python' %}
class Band(models.Model):
    """A model of a rock band."""
    name = models.CharField(max_length=200)
    can_rock = models.BooleanField(default=True)


class Member(models.Model):
    """A model of a rock band member."""
    name = models.CharField("Member's name", max_length=200)
    instrument = models.CharField(choices=(
            ('g', "Guitar"),
            ('b', "Bass"),
            ('d', "Drums"),
        ),
        max_length=1
    )
    band = models.ForeignKey("Band")
      {% endpygment %}
    </div>
  </li>
  <li>
    <h2>URLs and views</h2>
    <div class="collapsing-content">
      <p>A clean, elegant URL scheme is an important detail in a high-quality Web application. Django encourages beautiful URL design and doesn’t put any cruft in URLs, like .php or .asp.</p>
      <p>To design URLs for an application, you create a Python module called a URLconf. Like a table of contents for your app, it contains a simple mapping between URL patterns and your views.</p>
      <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/http/urls' host 'docs' %}">Read more</a>
      {% pygment 'python' %}
from django.urls import path

from . import views

urlpatterns = [
    path('bands/', views.band_listing, name='band-list'),
    path('bands/<int:band_id>/', views.band_detail, name='band-detail'),
    path('bands/search/', views.band_search, name='band-search'),
]
      {% endpygment %}
      {% pygment 'python' %}
from django.shortcuts import render

def band_listing(request):
    """A view of all bands."""
    bands = models.Band.objects.all()
    return render(request, 'bands/band_listing.html', {'bands': bands})
      {% endpygment %}
    </div>
  </li>
  <li>
    <h2>Templates</h2>
    <div class="collapsing-content">
      <p>Django’s template language is designed to strike a balance between power and ease. It’s designed to feel comfortable and easy-to-learn to those used to working with HTML, like designers and front-end developers. But it is also flexible and highly extensible, allowing developers to augment the template language as needed.</p>
      <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/templates' host 'docs' %}">Read more</a>
      {# No need to escape the HTML: pygment takes care of that #}
      {% pygment 'django' %}
{% verbatim %}
<html>
  <head>
    <title>Band Listing</title>
  </head>
  <body>
    <h1>All Bands</h1>
    <ul>
    {% for band in bands %}
      <li>
        <h2><a href="{{ band.get_absolute_url }}">{{ band.name }}</a></h2>
        {% if band.can_rock %}<p>This band can rock!</p>{% endif %}
      </li>
    {% endfor %}
    </ul>
  </body>
</html>
{% endverbatim %}
      {% endpygment %}
    </div>
  </li>
  <li>
    <h2>Forms</h2>
    <div class="collapsing-content">
      <p>Django provides a powerful form library that handles rendering forms as HTML, validating user-submitted data, and converting that data to native Python types. Django also provides a way to generate forms from your existing models and use those forms to create and update data.</p>
      <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/forms' host 'docs' %}">Read more</a>
      {% pygment 'python'%}
from django import forms

class BandContactForm(forms.Form):
    subject = forms.CharField(max_length=100)
    message = forms.CharField()
    sender = forms.EmailField()
    cc_myself = forms.BooleanField(required=False)
      {% endpygment %}
    </div>
  </li>
  <li>
    <h2>Authentication</h2>
    <div class="collapsing-content">
      <p>Django comes with a full-featured and secure authentication system. It handles user accounts, groups, permissions and cookie-based user sessions. This lets you easily build sites that allow users to create accounts and safely log in/out.</p>
      <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/auth' host 'docs' %}">Read more</a>
      {% pygment 'python' %}
from django.contrib.auth.decorators import login_required
from django.shortcuts import render

@login_required
def my_protected_view(request):
    """A view that can only be accessed by logged-in users"""
    return render(request, 'protected.html', {'current_user': request.user})
      {% endpygment %}
    </div>
  </li>
  <li>
    <h2>Admin</h2>
    <div class="collapsing-content">
      <p>One of the most powerful parts of Django is its automatic admin interface. It reads metadata in your models to provide a powerful and production-ready interface that content producers can immediately use to start managing content on your site. It’s easy to set up and provides many hooks for customization.</p>
      <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='ref/contrib/admin' host 'docs' %}">Read more</a>
      {% pygment 'python' %}
from django.contrib import admin
from bands.models import Band, Member

class MemberAdmin(admin.ModelAdmin):
    """Customize the look of the auto-generated admin for the Member model"""
    list_display = ('name', 'instrument')
    list_filter = ('band',)

admin.site.register(Band)  # Use the default options
admin.site.register(Member, MemberAdmin)  # Use the customized options
      {% endpygment %}
    </div>
  </li>
  <li>
    <h2>Internationalization</h2>
    <div class="collapsing-content">
      <p>Django offers full support for translating text into different languages, plus locale-specific formatting of dates, times, numbers, and time zones. It lets developers and template authors specify which parts of their apps should be translated or formatted for local languages and cultures, and it uses these hooks to localize Web applications for particular users according to their preferences.</p>
      <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/i18n' host 'docs' %}">Read more</a>

      {% pygment 'python' %}
from django.shortcuts import render
from django.utils.translation import gettext

def homepage(request):
    """
    Shows the homepage with a welcome message that is translated in the
    user's language.
    """
    message = gettext('Welcome to our site!')
    return render(request, 'homepage.html', {'message': message})
      {% endpygment %}

      {# No need to escape the HTML: pygment takes care of that #}
      {% pygment 'django' %}
{% verbatim %}
{% load i18n %}
<html>
  <head>
    <title>{% trans 'Homepage - Hall of Fame' %}</title>
  </head>
  <body>
    {# Translated in the view: #}
    <h1>{{ message }}</h1>
    <p>
      {% blocktrans count member_count=bands.count %}
      Here is the only band in the hall of fame:
      {% plural %}
      Here are all the {{ member_count }} bands in the hall of fame:
      {% endblocktrans %}
    </p>
    <ul>
    {% for band in bands %}
      <li>
        <h2><a href="{{ band.get_absolute_url }}">{{ band.name }}</a></h2>
        {% if band.can_rock %}<p>{% trans 'This band can rock!' %}</p>{% endif %}
      </li>
    {% endfor %}
    </ul>
  </body>
</html>
{% endverbatim %}
      {% endpygment %}
    </div>
  </li>
  <li>
    <h2>Security</h2>
    <div class="collapsing-content">
      <p>Django provides multiple protections against:</p>
      <ul>
        <li>Clickjacking</li>
        <li>Cross-site scripting</li>
        <li>Cross Site Request Forgery (CSRF)</li>
        <li>SQL injection</li>
        <li>Remote code execution</li>
      </ul>

      <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/security' host 'docs' %}">Read more</a>

    </div>
  </li>
</ul>

{% endblock %}
